﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace goAlarmsCS
{
    class AlarmFactory
    {
        public static IAlarm GetAlarm(AlarmTypes alarmType)  //factory ensures that correct alarm is returned and right func pointer for trigger creator.
        {
            IAlarm alarm;
            switch (alarmType)
            {
                //case AlarmTypes.Appointment:

                //    break;
                //case AlarmTypes.DailyScheduled:

                //    break;
                //case AlarmTypes.DailyTask:

                //    break;
                case AlarmTypes.Heartbeat:
                    alarm = HeartbeatAlarm.GetAlarm();
                    alarm.CreateTriggerFunction = QuartzAlarmScheduler.CreateMinutelyTrigger;
                    return alarm;

                //case AlarmTypes.OneTime:

                //    break;
                //case AlarmTypes.Random:

                //    break;
                //case AlarmTypes.Task:

                //    break;

                default:
                    throw new ArgumentException(String.Format("Unrecognized AlarmType: {0}", alarmType));
            }
        }

        static IAlarm _getAlarm<T>() where T : IAlarm
        {
            Type type = typeof(T);
            if (type.Equals(typeof(HeartbeatAlarm)))
                return GetHeartbeatAlarm();
            else
                throw new ArgumentException(String.Format("Unrecognized generic Alarm argument: {0}", type.FullName));
        }

        public static T GetAlarm<T>() where T : IAlarm
        {
            return (T)_getAlarm<T>();
        }

        public static IAlarm GetHeartbeatAlarm()
        {
            IAlarm alarm = HeartbeatAlarm.GetAlarm();
            //alarm.CreateTriggerFunction = QuartzAlarmScheduler.CreateMinutelyTrigger;
            return alarm;
        } 


#if Debug
        public static Alarm GetAlarmForTest(AlarmTypes alarmType,Func<CreateTriggerArgs,IAlarmTrigger> createTriggerArg)  //factory ensures that correct alarm is returned and right func pointer for trigger creator.
        {
            switch (alarmType)
            {
                case AlarmTypes.Appointment:

                    break;
                case AlarmTypes.DailyScheduled:

                    break;
                case AlarmTypes.DailyTask:

                    break;
                case AlarmTypes.Heartbeat:

                    break;
                case AlarmTypes.OneTime:

                    break;
                case AlarmTypes.Random:

                    break;
                case AlarmTypes.Task:

                    break;

                default:

                    break;
            }
        }
#endif
    }
}
